package com.shouldibuythis.android.component.quesions;

import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.shouldibuythis.android.R;
import com.shouldibuythis.android.models.Question;

import java.util.ArrayList;
import java.util.Date;

public class QuestionsActivity extends Activity {

    private ListView questionList;
    private QuestionsAdapter questionsAdapter;
    private Activity activity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = this;
        setContentView(R.layout.activity_questions);

        if(savedInstanceState == null){
            ArrayList<Question> questions = new ArrayList<Question>();

            Question question = new Question();
            question.setCreationDate(new Date());
            question.setUserName("Susan");
            question.setStatus("Accepted");
            question.setDescription("Should I buy this blouse");

            Question question1 = new Question();
            question1.setCreationDate(new Date());
            question1.setUserName("Maria");
            question1.setStatus("W/e");
            question1.setDescription("Whachha think?");

            Question question2 = new Question();
            question2.setCreationDate(new Date());
            question2.setUserName("Betty");
            question2.setStatus("Accepted");
            question2.setDescription("What about this one?");

            questions.add(question);
            questions.add(question1);
            questions.add(question2);

            questions.add(question);
            questions.add(question1);
            questions.add(question2);

            questionList = (ListView) findViewById(R.id.list_questions);
            questionsAdapter = new QuestionsAdapter(this, R.layout.list_item_question, questions);
            questionList.setAdapter(questionsAdapter);

            questionList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Intent intent = new Intent(activity, QuestionDetailActivity.class);
                    startActivity(intent);
                }
            });
        }

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_add_new_question:
                Intent intent = new Intent(this, QuestionAddActivity.class);
                startActivity(intent);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.question_add, menu);
        return true;
    }
    
}
